// 权限管理模块中所有的的接口
import request from './request'

// 用户管理模块
const controller = '/fmms/userController'

//#region
// 获取用户列表
export const getUserListByPageInfo = (queryForm) => {
  return request({
    url: `${controller}/getUserListByPageInfo/${queryForm.pageNo}/${queryForm.pageSize}`,
    // 这里的params应该传递一个对象然后会自动拼接到url中{name:'张三'}
    // 以下是为了省事把所有参数都传递过去了，后端会将需要的参数取出来，因此无所谓了
    params: queryForm,
    method: 'get'
  })
}

// 修改和增加用户 只适用于一次增加或修改一个用户
export const addOrModifyUser = (user) => {
  return request({
    url: `${controller}/addOrModifyUser`,
    params: user,
    data: user,
    method: 'put'
  })
}

// 批量删除用户
export const deleteUserByIds = (data) => {
  return request({
    url: `${controller}/deleteUserByIds`,
    method: 'delete',
    data
  })
}

//#endregion

// 角色管理模块
const controllerRole = '/fmms/roleController'

//#region
// 给用户分配角色
export const assignRoleByUserId = (userId, data) => {
  return request({
    url: `${controllerRole}/assignRoleByUserId/${userId}`,
    method: 'post',
    data
  })
}

// 获取所有角色信息
export const getAllRoleList = () => {
  return request({
    url: `${controllerRole}/getAllRoleList`,
    method: 'get'
  })
}

// 获取当前页的角色信息列表+模糊查询
export const getRoleListByOption = (roleQuery) => {
  return request({
    url: `${controllerRole}/getRoleListByOption/${roleQuery.pageNo}/${roleQuery.pageSize}`,
    params: roleQuery,
    method: 'get'
  })
}

// 获取用户的角色信息
export const getUserRoleListById = (userId) => {
  return request({
    url: `${controllerRole}/getUserRoleListById`,
    params: userId,
    method: 'get'
  })
}

// 添加或修改角色
export const addOrModifyRole = (data) => {
  return request({
    url: `${controllerRole}/addOrModifyRole`,
    method: 'put',
    data
  })
}

// 删除角色
export const deleteRoleByIds = (roleIds) => {
  return request({
    url: `${controllerRole}/deleteRoleByIds`,
    method: 'delete',
    data: roleIds
  })
}

//#endregion

// 菜单管理模块
const permissionController = '/fmms/permissionController'

// 获取全部菜单
export const getAllMenuList = () => {
  return request({
    url: `${permissionController}/getAllMenuList`,
    method: 'get'
  })
}

// 根据角色Id获取对应的菜单权限
export const getMenuListByRoleId = (roleId) => {
  return request({
    url: `${permissionController}/getMenuList/${roleId}`,
    method: 'get'
  })
}

// 给角色分配菜单
export const doAssign = (roleId, data) => {
  return request({
    url: `${permissionController}/doAssign`,
    params: roleId,
    data,
    method: 'post'
  })
}

// 增加菜单
export const addMenuList = (data) => {
  return request({
    url: `${permissionController}/addMenuList`,
    method: 'post',
    data
  })
}

// 修改菜单
export const updateMenuList = (data) => {
  return request({
    url: `${permissionController}/updateMenuList`,
    method: 'put',
    data
  })
}

// 删除菜单
export const removeMenuList = (id) => {
  return request({
    url: `${permissionController}/remove/${id}`,
    method: 'delete'
  })
}
